SlideShare a Scribd company logo
1 of 30
Dennis De Cock
PHPBenelux meeting, 2010, Houthalen
About me
 Independent consultant
 Owner of DE COCK ICT, company specialized in PHP / ZF / Drupal
development
Sponsors
About this presentation
 The intro
 Requirements
 Creating and loading
 Saving
 Working with pages
 Page sizes
 Duplication and cloning
 Colors & fonts
 Text & image drawing
 Styles
 Advanced topics
Zend_PDF: the intro
 Create or load pdf files
 Manipulate pages within documents, reorder, delete, and so on…
 Drawing possibilities for shapes, lines, …)
 Drawing of text using 14 built-in fonts or use own TrueType Fonts
 Image drawing (JPG, PNG [Up to 8bit per channel+Alpha] and TIFF images
are supported)
Requirements
 Zend_PDF is a component that can be found in the standard Zend library
 Latest Zend library available from http://framework.zend.com/download/latest
Folder structure
How to integrate
 Use the autoloader for automatic load of the module when needed (or load it
yourself without ) :
protected function _initAutoload() {
$moduleLoader = new Zend_Application_Module_Autoloader(
array(
'namespace' => ‘demo',
'basePath' => APPLICATION_PATH
)
);
return $moduleLoader;
}
Creating and loading
 One way to create a new pdf document:
 Two ways to load an existing document:
 Load it from a file:
 Load it from a string:
$pdf = new Zend_Pdf();
$pdf = Zend_Pdf::load($fileName);
$pdf = Zend_Pdf::parse($pdfString);
Saving
 Save a pdf document as a file:
 Update an existing file by using true as second parameter:
 You can also render the pdf to a string (example for passing through http)
$pdf->save(‘demo.pdf');
$pdf->save(‘demo.pdf‘, true);
$pdfData = $pdf->render();
Working with pages
 Add a page to an existing file:
 Remove a page from an existing file:
 Reverse page order:
$page = $pdf->newPage(Zend_Pdf_Page::SIZE_A4);
$pdf->pages[] = $page;
unset($pdf->pages[$id]);
$pdf->pages = array_reverse($pdf->pages);
Page sizes, some possibilities
 Specify a specific size:
Some other possibilities are:
 Use x and y coords to define your page:
$page = $pdf->newPage(Zend_Pdf_Page::SIZE_A4);
$pdf->pages[] = $page;
$page = $pdf->newPage(200, 400);
$pdf->pages[] = $page;
Zend_Pdf_Page::SIZE_A4_LANDSCAPE
Zend_Pdf_Page::SIZE_LETTER
Zend_Pdf_Page::SIZE_LETTER_LANDSCAPE
Page sizes, some possibilities
 Get the height and width from a pdf page:
$page = $pdf->pages[$id];
$width = $page->getWidth();
$height = $page->getHeight();
Duplicating pages
 Duplicate a page from a pdf document to create pages faster
 Duplicated pages share resources from the template page so you can only duplicate
within the same file
// Store template page in a separate variable
$template = $pdf->pages[$templatePageIndex];
// Add new page
$page1 = new Zend_Pdf_Page($template);
$page1->drawText('Some text...', $x, $y);
$pdf->pages[] = $page1;
Cloning pages
 Clone a page from any document. PDF resources are copied, so you are
not bound to the same document.
$page1 = clone $pdf1->pages[$templatePageIndex1];
$page2 = clone $pdf2->pages[$templatePageIndex2];
$page1->drawText('Some text...', $x, $y);
$page2->drawText('Another text...', $x, $y);
$pdf = new Zend_Pdf();
$pdf->pages[] = $page1;
$pdf->pages[] = $page2;
Colors
 Zend_Pdf_Color supports grayscale, rgb and cmyk
 Html style colors are also supported through Zend_Pdf_Color_Html
// $grayLevel (float number). 0.0 (black) - 1.0 (white)
$color1 = new Zend_Pdf_Color_GrayScale($grayLevel);
// $r, $g, $b (float numbers). 0.0 (min intensity) - 1.0 (max intensity)
$color2 = new Zend_Pdf_Color_Rgb($r, $g, $b);
// $c, $m, $y, $k (float numbers). 0.0 (min intensity) - 1.0 (max intensity)
$color3 = new Zend_Pdf_Color_Cmyk($c, $m, $y, $k);
$color1 = new Zend_Pdf_Color_Html('#3366FF');
Fonts at your disposal
 Specify a font to use:
Some other possibilities are:
$page->setFont(Zend_Pdf_Font::fontWithName(Zend_Pdf_Font::FONT_HELVETICA),
12);
Zend_Pdf_Font::FONT_COURIER
Zend_Pdf_Font::FONT_COURIER_BOLD
Zend_Pdf_Font::FONT_COURIER_ITALIC
Zend_Pdf_Font::FONT_COURIER_BOLD_ITALIC
Zend_Pdf_Font::FONT_TIMES
Zend_Pdf_Font::FONT_TIMES_BOLD
Zend_Pdf_Font::FONT_TIMES_ITALIC
Zend_Pdf_Font::FONT_TIMES_BOLD_ITALIC
Zend_Pdf_Font::FONT_HELVETICA
Zend_Pdf_Font::FONT_HELVETICA_BOLD
Zend_Pdf_Font::FONT_HELVETICA_ITALIC
Zend_Pdf_Font::FONT_HELVETICA_BOLD_ITALIC
Zend_Pdf_Font::FONT_SYMBOL
Zend_Pdf_Font::FONT_ZAPFDINGBATS
Use your own fonts
 Only truetype fonts can be used, create the font:
 Then use the font on the page:
$myFont = Zend_Pdf_Font::fontWithPath('/path/to/my/special/font__.TTF');
$page->setFont($myFont, 12);
An error with a custom font?
 Errors can arise with embedding the font into the file or compressing the font.
 You can use the following options to handle these errors:
 Zend_Pdf_Font::EMBED_DONT_EMBED
Do not embed the font
 Zend_Pdf_Font::EMBED_SUPPRESS_EMBED_EXCEPTION
Do not throw the error
 Zend_Pdf_Font::EMBED_DONT_COMPRESS
Do not compress
 You can combine the above options to match your specific solution.
Adding text to the page
 Function drawtext needs 3 parameters
drawText($text, $x, $y);
 Optional you can specify character encoding as fourth parameter:
drawText($text, $x, $y, $charEncoding = ‘’);
 Example:
$page->drawText('Hello world!', 50, 600 );
Adding shapes to the page
 Different possibilities for shape drawing:
 drawLine($x1, $y1, $x2, $y2)
 drawRectangle($x1, $y1, $x2, $y2,
$fillType =
Zend_Pdf_Page::SHAPE_DRAW_FILL_AND_STROKE)
 drawRoundedRectangle($x1, $y1, $x2, $y2, $radius,
$fillType =
Zend_Pdf_Page::SHAPE_DRAW_FILL_AND_STROKE)
 drawPolygon($x, $y, $fillType =
Zend_Pdf_Page::SHAPE_DRAW_FILL_AND_STROKE,
$fillMethod =
Zend_Pdf_Page::FILL_METHOD_NON_ZERO_WINDING)
 drawCircle($x, $y, $radius, $param4 = null, $param5 = null, $param6 = null)
Adding images to the page
 JPG, PNG and TIFF images are now supported
 An example:
// Load the image
$image = Zend_Pdf_Image::imageWithPath(APPLICATION_FRONT .
'/images/logo.tif');
// Draw image
$page->drawImage($image, 40, 764, 240, 820);
// -> $image, $left, $bottom, $right, $top
An example in detail
 Here’s a more complete example and the result:
$pdf = new Zend_Pdf();
$page = $pdf->newPage(Zend_Pdf_Page::SIZE_A4);
$pdf->pages[] = $page;
$page->setFont(Zend_Pdf_Font::fontWithName(
Zend_Pdf_Font::FONT_HELVETICA), 12);
$page->drawText('Hello world!', 50, 600 );
$image = Zend_Pdf_Image::imageWithPath(APPLICATION_FRONT .
'/images/logo.tif');
$page->drawImage($image, 40, 764, 240, 820);
$page->drawLine(50, 755, 545, 755);
$pdf->save('demo.pdf');
The result
Using styles
 Create styles to combine your own specific layout of pdf in one place:
 After creating the style, add some elements to your style
 Apply the style
$mystyle = new Zend_Pdf_Style();
$mystyle->setFont(Zend_Pdf_Font::fontWithName(
Zend_Pdf_Font::FONT_HELVETICA), 12);
$mystyle->Zend_Pdf_Color_Rgb(1, 1, 0));
$mystyle->setLineWidth(1);
$page1->setStyle($mystyle);
Document info
 Add information to your document through the properties:
$pdf = Zend_Pdf::load($pdfPath);
echo $pdf->properties[‘Demo'] . "n";
echo $pdf->properties[‘Dennis'] . "n";
$pdf->properties['Title'] = ‘Demo';
$pdf->save($pdfPath);
Advanced topics
 Zend_Pdf_Resource_Extractor class for cloning pages and share resources
through the different templates
 Linear transformations, most of them are available as from ZF 1,8
(skew, scale, …)
Summary
 Zend_PDF has powerful capabilities
 Combining the extended pdf class on framework.zend.com makes life a little
easier
Recommended reading
http://devzone.zend.com/article/2525
Zend_PDF tutorial by Cal Evans
Thank you!
Questions?

More Related Content

What's hot

Learning needs assessment 1.pptx
Learning needs assessment 1.pptxLearning needs assessment 1.pptx
Learning needs assessment 1.pptxHeather Lagran
 
SCRUM арга
SCRUM аргаSCRUM арга
SCRUM аргаUndram J
 
Budgeting for schools
Budgeting for schoolsBudgeting for schools
Budgeting for schoolsPaul Lower
 
ራስን የማብቃት ዕቅድ የዕቅዱ ባለቤት፡-ብርሃኑ ታደሰ 2007 -_copy_doc
ራስን የማብቃት ዕቅድ የዕቅዱ ባለቤት፡-ብርሃኑ ታደሰ  2007 -_copy_docራስን የማብቃት ዕቅድ የዕቅዱ ባለቤት፡-ብርሃኑ ታደሰ  2007 -_copy_doc
ራስን የማብቃት ዕቅድ የዕቅዱ ባለቤት፡-ብርሃኑ ታደሰ 2007 -_copy_docberhanu taye
 
800.mn - 2012 Математик ЭЕШ хувилбар А by byambaa avirmed
800.mn - 2012 Математик ЭЕШ хувилбар А by byambaa avirmed800.mn - 2012 Математик ЭЕШ хувилбар А by byambaa avirmed
800.mn - 2012 Математик ЭЕШ хувилбар А by byambaa avirmedБямбаа Авирмэд
 
хичээл 6
хичээл 6хичээл 6
хичээл 6Ankhaa
 
النهضة العربية
النهضة العربيةالنهضة العربية
النهضة العربيةcheikh bembary
 
томъёо
томъёотомъёо
томъёоjuuyaar
 
20142022 berhanu training_education_development_need_assessment [read-only]
20142022 berhanu training_education_development_need_assessment [read-only]20142022 berhanu training_education_development_need_assessment [read-only]
20142022 berhanu training_education_development_need_assessment [read-only]berhanu taye
 
800.mn - 2009 Математик ЭЕШ by byambaa avirmed
800.mn - 2009 Математик ЭЕШ by byambaa avirmed800.mn - 2009 Математик ЭЕШ by byambaa avirmed
800.mn - 2009 Математик ЭЕШ by byambaa avirmedБямбаа Авирмэд
 
Lab14 algorithm
Lab14 algorithmLab14 algorithm
Lab14 algorithmBPurev
 
9 р анги тест
9 р анги тест9 р анги тест
9 р анги тестSainaa0831
 

What's hot (13)

Power point 2007 хичээлүүд
Power point 2007 хичээлүүдPower point 2007 хичээлүүд
Power point 2007 хичээлүүд
 
Learning needs assessment 1.pptx
Learning needs assessment 1.pptxLearning needs assessment 1.pptx
Learning needs assessment 1.pptx
 
SCRUM арга
SCRUM аргаSCRUM арга
SCRUM арга
 
Budgeting for schools
Budgeting for schoolsBudgeting for schools
Budgeting for schools
 
ራስን የማብቃት ዕቅድ የዕቅዱ ባለቤት፡-ብርሃኑ ታደሰ 2007 -_copy_doc
ራስን የማብቃት ዕቅድ የዕቅዱ ባለቤት፡-ብርሃኑ ታደሰ  2007 -_copy_docራስን የማብቃት ዕቅድ የዕቅዱ ባለቤት፡-ብርሃኑ ታደሰ  2007 -_copy_doc
ራስን የማብቃት ዕቅድ የዕቅዱ ባለቤት፡-ብርሃኑ ታደሰ 2007 -_copy_doc
 
800.mn - 2012 Математик ЭЕШ хувилбар А by byambaa avirmed
800.mn - 2012 Математик ЭЕШ хувилбар А by byambaa avirmed800.mn - 2012 Математик ЭЕШ хувилбар А by byambaa avirmed
800.mn - 2012 Математик ЭЕШ хувилбар А by byambaa avirmed
 
хичээл 6
хичээл 6хичээл 6
хичээл 6
 
النهضة العربية
النهضة العربيةالنهضة العربية
النهضة العربية
 
томъёо
томъёотомъёо
томъёо
 
20142022 berhanu training_education_development_need_assessment [read-only]
20142022 berhanu training_education_development_need_assessment [read-only]20142022 berhanu training_education_development_need_assessment [read-only]
20142022 berhanu training_education_development_need_assessment [read-only]
 
800.mn - 2009 Математик ЭЕШ by byambaa avirmed
800.mn - 2009 Математик ЭЕШ by byambaa avirmed800.mn - 2009 Математик ЭЕШ by byambaa avirmed
800.mn - 2009 Математик ЭЕШ by byambaa avirmed
 
Lab14 algorithm
Lab14 algorithmLab14 algorithm
Lab14 algorithm
 
9 р анги тест
9 р анги тест9 р анги тест
9 р анги тест
 

Similar to Introduction to Zend_Pdf

Advanced Drupal Views: Theming your View
Advanced Drupal Views: Theming your ViewAdvanced Drupal Views: Theming your View
Advanced Drupal Views: Theming your ViewRyan Cross
 
The Render API in Drupal 7
The Render API in Drupal 7The Render API in Drupal 7
The Render API in Drupal 7frandoh
 
The FPDF Library
The FPDF LibraryThe FPDF Library
The FPDF LibraryDave Ross
 
Drupal vs WordPress
Drupal vs WordPressDrupal vs WordPress
Drupal vs WordPressWalter Ebert
 
8 things to know about theming in drupal 8
8 things to know about theming in drupal 88 things to know about theming in drupal 8
8 things to know about theming in drupal 8Logan Farr
 
Disregard Inputs, Acquire Zend_Form
Disregard Inputs, Acquire Zend_FormDisregard Inputs, Acquire Zend_Form
Disregard Inputs, Acquire Zend_FormDaniel Cousineau
 
TDC2017 | São Paulo - Trilha Programação Funcional How we figured out we had ...
TDC2017 | São Paulo - Trilha Programação Funcional How we figured out we had ...TDC2017 | São Paulo - Trilha Programação Funcional How we figured out we had ...
TDC2017 | São Paulo - Trilha Programação Funcional How we figured out we had ...tdc-globalcode
 
Introduction to Plugin Programming, WordCamp Miami 2011
Introduction to Plugin Programming, WordCamp Miami 2011Introduction to Plugin Programming, WordCamp Miami 2011
Introduction to Plugin Programming, WordCamp Miami 2011David Carr
 
Zend Framework Study@Tokyo #2
Zend Framework Study@Tokyo #2Zend Framework Study@Tokyo #2
Zend Framework Study@Tokyo #2Shinya Ohyanagi
 
Zend Framework Components for non-framework Development
Zend Framework Components for non-framework DevelopmentZend Framework Components for non-framework Development
Zend Framework Components for non-framework DevelopmentShahar Evron
 
Display Suite: A Themers Perspective
Display Suite: A Themers PerspectiveDisplay Suite: A Themers Perspective
Display Suite: A Themers PerspectiveMediacurrent
 
Zend framework 06 - zend config, pdf, i18n, l10n, sessions
Zend framework 06 - zend config, pdf, i18n, l10n, sessionsZend framework 06 - zend config, pdf, i18n, l10n, sessions
Zend framework 06 - zend config, pdf, i18n, l10n, sessionsTricode (part of Dept)
 
Drupaljam xl 2019 presentation multilingualism makes better programmers
Drupaljam xl 2019 presentation   multilingualism makes better programmersDrupaljam xl 2019 presentation   multilingualism makes better programmers
Drupaljam xl 2019 presentation multilingualism makes better programmersAlexander Varwijk
 
Model-View-Update, and Beyond!
Model-View-Update, and Beyond!Model-View-Update, and Beyond!
Model-View-Update, and Beyond!Simon Fowler
 
EPiServer report generation
EPiServer report generationEPiServer report generation
EPiServer report generationPaul Graham
 
DrupalTour. Rivne — Drupal 8 (Ivan Tibezh, InternetDevels)
DrupalTour. Rivne — Drupal 8 (Ivan Tibezh, InternetDevels)DrupalTour. Rivne — Drupal 8 (Ivan Tibezh, InternetDevels)
DrupalTour. Rivne — Drupal 8 (Ivan Tibezh, InternetDevels)Drupaltour
 
Vancouver League of Drupallers - Remembering the User (August 2008)
Vancouver League of Drupallers - Remembering the User (August 2008)Vancouver League of Drupallers - Remembering the User (August 2008)
Vancouver League of Drupallers - Remembering the User (August 2008)baronmunchowsen
 
Kicking off with Zend Expressive and Doctrine ORM (PHP Srbija 2017)
Kicking off with Zend Expressive and Doctrine ORM (PHP Srbija 2017)Kicking off with Zend Expressive and Doctrine ORM (PHP Srbija 2017)
Kicking off with Zend Expressive and Doctrine ORM (PHP Srbija 2017)James Titcumb
 
Introduction to Zend framework
Introduction to Zend framework Introduction to Zend framework
Introduction to Zend framework Matteo Magni
 

Similar to Introduction to Zend_Pdf (20)

Advanced Drupal Views: Theming your View
Advanced Drupal Views: Theming your ViewAdvanced Drupal Views: Theming your View
Advanced Drupal Views: Theming your View
 
The Render API in Drupal 7
The Render API in Drupal 7The Render API in Drupal 7
The Render API in Drupal 7
 
The FPDF Library
The FPDF LibraryThe FPDF Library
The FPDF Library
 
Drupal vs WordPress
Drupal vs WordPressDrupal vs WordPress
Drupal vs WordPress
 
8 things to know about theming in drupal 8
8 things to know about theming in drupal 88 things to know about theming in drupal 8
8 things to know about theming in drupal 8
 
Disregard Inputs, Acquire Zend_Form
Disregard Inputs, Acquire Zend_FormDisregard Inputs, Acquire Zend_Form
Disregard Inputs, Acquire Zend_Form
 
TDC2017 | São Paulo - Trilha Programação Funcional How we figured out we had ...
TDC2017 | São Paulo - Trilha Programação Funcional How we figured out we had ...TDC2017 | São Paulo - Trilha Programação Funcional How we figured out we had ...
TDC2017 | São Paulo - Trilha Programação Funcional How we figured out we had ...
 
Introduction to Plugin Programming, WordCamp Miami 2011
Introduction to Plugin Programming, WordCamp Miami 2011Introduction to Plugin Programming, WordCamp Miami 2011
Introduction to Plugin Programming, WordCamp Miami 2011
 
Zend Framework Study@Tokyo #2
Zend Framework Study@Tokyo #2Zend Framework Study@Tokyo #2
Zend Framework Study@Tokyo #2
 
Zend Framework Components for non-framework Development
Zend Framework Components for non-framework DevelopmentZend Framework Components for non-framework Development
Zend Framework Components for non-framework Development
 
Display Suite: A Themers Perspective
Display Suite: A Themers PerspectiveDisplay Suite: A Themers Perspective
Display Suite: A Themers Perspective
 
Zend framework 06 - zend config, pdf, i18n, l10n, sessions
Zend framework 06 - zend config, pdf, i18n, l10n, sessionsZend framework 06 - zend config, pdf, i18n, l10n, sessions
Zend framework 06 - zend config, pdf, i18n, l10n, sessions
 
Drupaljam xl 2019 presentation multilingualism makes better programmers
Drupaljam xl 2019 presentation   multilingualism makes better programmersDrupaljam xl 2019 presentation   multilingualism makes better programmers
Drupaljam xl 2019 presentation multilingualism makes better programmers
 
Model-View-Update, and Beyond!
Model-View-Update, and Beyond!Model-View-Update, and Beyond!
Model-View-Update, and Beyond!
 
EPiServer report generation
EPiServer report generationEPiServer report generation
EPiServer report generation
 
DrupalTour. Rivne — Drupal 8 (Ivan Tibezh, InternetDevels)
DrupalTour. Rivne — Drupal 8 (Ivan Tibezh, InternetDevels)DrupalTour. Rivne — Drupal 8 (Ivan Tibezh, InternetDevels)
DrupalTour. Rivne — Drupal 8 (Ivan Tibezh, InternetDevels)
 
Vancouver League of Drupallers - Remembering the User (August 2008)
Vancouver League of Drupallers - Remembering the User (August 2008)Vancouver League of Drupallers - Remembering the User (August 2008)
Vancouver League of Drupallers - Remembering the User (August 2008)
 
WEB DEVELOPMENT
WEB DEVELOPMENTWEB DEVELOPMENT
WEB DEVELOPMENT
 
Kicking off with Zend Expressive and Doctrine ORM (PHP Srbija 2017)
Kicking off with Zend Expressive and Doctrine ORM (PHP Srbija 2017)Kicking off with Zend Expressive and Doctrine ORM (PHP Srbija 2017)
Kicking off with Zend Expressive and Doctrine ORM (PHP Srbija 2017)
 
Introduction to Zend framework
Introduction to Zend framework Introduction to Zend framework
Introduction to Zend framework
 

Recently uploaded

WebAssembly is Key to Better LLM Performance
WebAssembly is Key to Better LLM PerformanceWebAssembly is Key to Better LLM Performance
WebAssembly is Key to Better LLM PerformanceSamy Fodil
 
Unpacking Value Delivery - Agile Oxford Meetup - May 2024.pptx
Unpacking Value Delivery - Agile Oxford Meetup - May 2024.pptxUnpacking Value Delivery - Agile Oxford Meetup - May 2024.pptx
Unpacking Value Delivery - Agile Oxford Meetup - May 2024.pptxDavid Michel
 
Extensible Python: Robustness through Addition - PyCon 2024
Extensible Python: Robustness through Addition - PyCon 2024Extensible Python: Robustness through Addition - PyCon 2024
Extensible Python: Robustness through Addition - PyCon 2024Patrick Viafore
 
WSO2CONMay2024OpenSourceConferenceDebrief.pptx
WSO2CONMay2024OpenSourceConferenceDebrief.pptxWSO2CONMay2024OpenSourceConferenceDebrief.pptx
WSO2CONMay2024OpenSourceConferenceDebrief.pptxJennifer Lim
 
The UX of Automation by AJ King, Senior UX Researcher, Ocado
The UX of Automation by AJ King, Senior UX Researcher, OcadoThe UX of Automation by AJ King, Senior UX Researcher, Ocado
The UX of Automation by AJ King, Senior UX Researcher, OcadoUXDXConf
 
Agentic RAG What it is its types applications and implementation.pdf
Agentic RAG What it is its types applications and implementation.pdfAgentic RAG What it is its types applications and implementation.pdf
Agentic RAG What it is its types applications and implementation.pdfChristopherTHyatt
 
AI presentation and introduction - Retrieval Augmented Generation RAG 101
AI presentation and introduction - Retrieval Augmented Generation RAG 101AI presentation and introduction - Retrieval Augmented Generation RAG 101
AI presentation and introduction - Retrieval Augmented Generation RAG 101vincent683379
 
Demystifying gRPC in .Net by John Staveley
Demystifying gRPC in .Net by John StaveleyDemystifying gRPC in .Net by John Staveley
Demystifying gRPC in .Net by John StaveleyJohn Staveley
 
PLAI - Acceleration Program for Generative A.I. Startups
PLAI - Acceleration Program for Generative A.I. StartupsPLAI - Acceleration Program for Generative A.I. Startups
PLAI - Acceleration Program for Generative A.I. StartupsStefano
 
A Business-Centric Approach to Design System Strategy
A Business-Centric Approach to Design System StrategyA Business-Centric Approach to Design System Strategy
A Business-Centric Approach to Design System StrategyUXDXConf
 
The Metaverse: Are We There Yet?
The  Metaverse:    Are   We  There  Yet?The  Metaverse:    Are   We  There  Yet?
The Metaverse: Are We There Yet?Mark Billinghurst
 
The Value of Certifying Products for FDO _ Paul at FIDO Alliance.pdf
The Value of Certifying Products for FDO _ Paul at FIDO Alliance.pdfThe Value of Certifying Products for FDO _ Paul at FIDO Alliance.pdf
The Value of Certifying Products for FDO _ Paul at FIDO Alliance.pdfFIDO Alliance
 
Powerful Start- the Key to Project Success, Barbara Laskowska
Powerful Start- the Key to Project Success, Barbara LaskowskaPowerful Start- the Key to Project Success, Barbara Laskowska
Powerful Start- the Key to Project Success, Barbara LaskowskaCzechDreamin
 
Buy Epson EcoTank L3210 Colour Printer Online.pptx
Buy Epson EcoTank L3210 Colour Printer Online.pptxBuy Epson EcoTank L3210 Colour Printer Online.pptx
Buy Epson EcoTank L3210 Colour Printer Online.pptxEasyPrinterHelp
 
UiPath Test Automation using UiPath Test Suite series, part 1
UiPath Test Automation using UiPath Test Suite series, part 1UiPath Test Automation using UiPath Test Suite series, part 1
UiPath Test Automation using UiPath Test Suite series, part 1DianaGray10
 
Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...
Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...
Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...CzechDreamin
 
Enterprise Knowledge Graphs - Data Summit 2024
Enterprise Knowledge Graphs - Data Summit 2024Enterprise Knowledge Graphs - Data Summit 2024
Enterprise Knowledge Graphs - Data Summit 2024Enterprise Knowledge
 
Intro in Product Management - Коротко про професію продакт менеджера
Intro in Product Management - Коротко про професію продакт менеджераIntro in Product Management - Коротко про професію продакт менеджера
Intro in Product Management - Коротко про професію продакт менеджераMark Opanasiuk
 
IESVE for Early Stage Design and Planning
IESVE for Early Stage Design and PlanningIESVE for Early Stage Design and Planning
IESVE for Early Stage Design and PlanningIES VE
 
Buy Epson EcoTank L3210 Colour Printer Online.pdf
Buy Epson EcoTank L3210 Colour Printer Online.pdfBuy Epson EcoTank L3210 Colour Printer Online.pdf
Buy Epson EcoTank L3210 Colour Printer Online.pdfEasyPrinterHelp
 

Recently uploaded (20)

WebAssembly is Key to Better LLM Performance
WebAssembly is Key to Better LLM PerformanceWebAssembly is Key to Better LLM Performance
WebAssembly is Key to Better LLM Performance
 
Unpacking Value Delivery - Agile Oxford Meetup - May 2024.pptx
Unpacking Value Delivery - Agile Oxford Meetup - May 2024.pptxUnpacking Value Delivery - Agile Oxford Meetup - May 2024.pptx
Unpacking Value Delivery - Agile Oxford Meetup - May 2024.pptx
 
Extensible Python: Robustness through Addition - PyCon 2024
Extensible Python: Robustness through Addition - PyCon 2024Extensible Python: Robustness through Addition - PyCon 2024
Extensible Python: Robustness through Addition - PyCon 2024
 
WSO2CONMay2024OpenSourceConferenceDebrief.pptx
WSO2CONMay2024OpenSourceConferenceDebrief.pptxWSO2CONMay2024OpenSourceConferenceDebrief.pptx
WSO2CONMay2024OpenSourceConferenceDebrief.pptx
 
The UX of Automation by AJ King, Senior UX Researcher, Ocado
The UX of Automation by AJ King, Senior UX Researcher, OcadoThe UX of Automation by AJ King, Senior UX Researcher, Ocado
The UX of Automation by AJ King, Senior UX Researcher, Ocado
 
Agentic RAG What it is its types applications and implementation.pdf
Agentic RAG What it is its types applications and implementation.pdfAgentic RAG What it is its types applications and implementation.pdf
Agentic RAG What it is its types applications and implementation.pdf
 
AI presentation and introduction - Retrieval Augmented Generation RAG 101
AI presentation and introduction - Retrieval Augmented Generation RAG 101AI presentation and introduction - Retrieval Augmented Generation RAG 101
AI presentation and introduction - Retrieval Augmented Generation RAG 101
 
Demystifying gRPC in .Net by John Staveley
Demystifying gRPC in .Net by John StaveleyDemystifying gRPC in .Net by John Staveley
Demystifying gRPC in .Net by John Staveley
 
PLAI - Acceleration Program for Generative A.I. Startups
PLAI - Acceleration Program for Generative A.I. StartupsPLAI - Acceleration Program for Generative A.I. Startups
PLAI - Acceleration Program for Generative A.I. Startups
 
A Business-Centric Approach to Design System Strategy
A Business-Centric Approach to Design System StrategyA Business-Centric Approach to Design System Strategy
A Business-Centric Approach to Design System Strategy
 
The Metaverse: Are We There Yet?
The  Metaverse:    Are   We  There  Yet?The  Metaverse:    Are   We  There  Yet?
The Metaverse: Are We There Yet?
 
The Value of Certifying Products for FDO _ Paul at FIDO Alliance.pdf
The Value of Certifying Products for FDO _ Paul at FIDO Alliance.pdfThe Value of Certifying Products for FDO _ Paul at FIDO Alliance.pdf
The Value of Certifying Products for FDO _ Paul at FIDO Alliance.pdf
 
Powerful Start- the Key to Project Success, Barbara Laskowska
Powerful Start- the Key to Project Success, Barbara LaskowskaPowerful Start- the Key to Project Success, Barbara Laskowska
Powerful Start- the Key to Project Success, Barbara Laskowska
 
Buy Epson EcoTank L3210 Colour Printer Online.pptx
Buy Epson EcoTank L3210 Colour Printer Online.pptxBuy Epson EcoTank L3210 Colour Printer Online.pptx
Buy Epson EcoTank L3210 Colour Printer Online.pptx
 
UiPath Test Automation using UiPath Test Suite series, part 1
UiPath Test Automation using UiPath Test Suite series, part 1UiPath Test Automation using UiPath Test Suite series, part 1
UiPath Test Automation using UiPath Test Suite series, part 1
 
Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...
Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...
Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...
 
Enterprise Knowledge Graphs - Data Summit 2024
Enterprise Knowledge Graphs - Data Summit 2024Enterprise Knowledge Graphs - Data Summit 2024
Enterprise Knowledge Graphs - Data Summit 2024
 
Intro in Product Management - Коротко про професію продакт менеджера
Intro in Product Management - Коротко про професію продакт менеджераIntro in Product Management - Коротко про професію продакт менеджера
Intro in Product Management - Коротко про професію продакт менеджера
 
IESVE for Early Stage Design and Planning
IESVE for Early Stage Design and PlanningIESVE for Early Stage Design and Planning
IESVE for Early Stage Design and Planning
 
Buy Epson EcoTank L3210 Colour Printer Online.pdf
Buy Epson EcoTank L3210 Colour Printer Online.pdfBuy Epson EcoTank L3210 Colour Printer Online.pdf
Buy Epson EcoTank L3210 Colour Printer Online.pdf
 

Introduction to Zend_Pdf

  • 1. Dennis De Cock PHPBenelux meeting, 2010, Houthalen
  • 2. About me  Independent consultant  Owner of DE COCK ICT, company specialized in PHP / ZF / Drupal development
  • 4. About this presentation  The intro  Requirements  Creating and loading  Saving  Working with pages  Page sizes  Duplication and cloning  Colors & fonts  Text & image drawing  Styles  Advanced topics
  • 5. Zend_PDF: the intro  Create or load pdf files  Manipulate pages within documents, reorder, delete, and so on…  Drawing possibilities for shapes, lines, …)  Drawing of text using 14 built-in fonts or use own TrueType Fonts  Image drawing (JPG, PNG [Up to 8bit per channel+Alpha] and TIFF images are supported)
  • 6. Requirements  Zend_PDF is a component that can be found in the standard Zend library  Latest Zend library available from http://framework.zend.com/download/latest
  • 8. How to integrate  Use the autoloader for automatic load of the module when needed (or load it yourself without ) : protected function _initAutoload() { $moduleLoader = new Zend_Application_Module_Autoloader( array( 'namespace' => ‘demo', 'basePath' => APPLICATION_PATH ) ); return $moduleLoader; }
  • 9. Creating and loading  One way to create a new pdf document:  Two ways to load an existing document:  Load it from a file:  Load it from a string: $pdf = new Zend_Pdf(); $pdf = Zend_Pdf::load($fileName); $pdf = Zend_Pdf::parse($pdfString);
  • 10. Saving  Save a pdf document as a file:  Update an existing file by using true as second parameter:  You can also render the pdf to a string (example for passing through http) $pdf->save(‘demo.pdf'); $pdf->save(‘demo.pdf‘, true); $pdfData = $pdf->render();
  • 11. Working with pages  Add a page to an existing file:  Remove a page from an existing file:  Reverse page order: $page = $pdf->newPage(Zend_Pdf_Page::SIZE_A4); $pdf->pages[] = $page; unset($pdf->pages[$id]); $pdf->pages = array_reverse($pdf->pages);
  • 12. Page sizes, some possibilities  Specify a specific size: Some other possibilities are:  Use x and y coords to define your page: $page = $pdf->newPage(Zend_Pdf_Page::SIZE_A4); $pdf->pages[] = $page; $page = $pdf->newPage(200, 400); $pdf->pages[] = $page; Zend_Pdf_Page::SIZE_A4_LANDSCAPE Zend_Pdf_Page::SIZE_LETTER Zend_Pdf_Page::SIZE_LETTER_LANDSCAPE
  • 13. Page sizes, some possibilities  Get the height and width from a pdf page: $page = $pdf->pages[$id]; $width = $page->getWidth(); $height = $page->getHeight();
  • 14. Duplicating pages  Duplicate a page from a pdf document to create pages faster  Duplicated pages share resources from the template page so you can only duplicate within the same file // Store template page in a separate variable $template = $pdf->pages[$templatePageIndex]; // Add new page $page1 = new Zend_Pdf_Page($template); $page1->drawText('Some text...', $x, $y); $pdf->pages[] = $page1;
  • 15. Cloning pages  Clone a page from any document. PDF resources are copied, so you are not bound to the same document. $page1 = clone $pdf1->pages[$templatePageIndex1]; $page2 = clone $pdf2->pages[$templatePageIndex2]; $page1->drawText('Some text...', $x, $y); $page2->drawText('Another text...', $x, $y); $pdf = new Zend_Pdf(); $pdf->pages[] = $page1; $pdf->pages[] = $page2;
  • 16. Colors  Zend_Pdf_Color supports grayscale, rgb and cmyk  Html style colors are also supported through Zend_Pdf_Color_Html // $grayLevel (float number). 0.0 (black) - 1.0 (white) $color1 = new Zend_Pdf_Color_GrayScale($grayLevel); // $r, $g, $b (float numbers). 0.0 (min intensity) - 1.0 (max intensity) $color2 = new Zend_Pdf_Color_Rgb($r, $g, $b); // $c, $m, $y, $k (float numbers). 0.0 (min intensity) - 1.0 (max intensity) $color3 = new Zend_Pdf_Color_Cmyk($c, $m, $y, $k); $color1 = new Zend_Pdf_Color_Html('#3366FF');
  • 17. Fonts at your disposal  Specify a font to use: Some other possibilities are: $page->setFont(Zend_Pdf_Font::fontWithName(Zend_Pdf_Font::FONT_HELVETICA), 12); Zend_Pdf_Font::FONT_COURIER Zend_Pdf_Font::FONT_COURIER_BOLD Zend_Pdf_Font::FONT_COURIER_ITALIC Zend_Pdf_Font::FONT_COURIER_BOLD_ITALIC Zend_Pdf_Font::FONT_TIMES Zend_Pdf_Font::FONT_TIMES_BOLD Zend_Pdf_Font::FONT_TIMES_ITALIC Zend_Pdf_Font::FONT_TIMES_BOLD_ITALIC Zend_Pdf_Font::FONT_HELVETICA Zend_Pdf_Font::FONT_HELVETICA_BOLD Zend_Pdf_Font::FONT_HELVETICA_ITALIC Zend_Pdf_Font::FONT_HELVETICA_BOLD_ITALIC Zend_Pdf_Font::FONT_SYMBOL Zend_Pdf_Font::FONT_ZAPFDINGBATS
  • 18. Use your own fonts  Only truetype fonts can be used, create the font:  Then use the font on the page: $myFont = Zend_Pdf_Font::fontWithPath('/path/to/my/special/font__.TTF'); $page->setFont($myFont, 12);
  • 19. An error with a custom font?  Errors can arise with embedding the font into the file or compressing the font.  You can use the following options to handle these errors:  Zend_Pdf_Font::EMBED_DONT_EMBED Do not embed the font  Zend_Pdf_Font::EMBED_SUPPRESS_EMBED_EXCEPTION Do not throw the error  Zend_Pdf_Font::EMBED_DONT_COMPRESS Do not compress  You can combine the above options to match your specific solution.
  • 20. Adding text to the page  Function drawtext needs 3 parameters drawText($text, $x, $y);  Optional you can specify character encoding as fourth parameter: drawText($text, $x, $y, $charEncoding = ‘’);  Example: $page->drawText('Hello world!', 50, 600 );
  • 21. Adding shapes to the page  Different possibilities for shape drawing:  drawLine($x1, $y1, $x2, $y2)  drawRectangle($x1, $y1, $x2, $y2, $fillType = Zend_Pdf_Page::SHAPE_DRAW_FILL_AND_STROKE)  drawRoundedRectangle($x1, $y1, $x2, $y2, $radius, $fillType = Zend_Pdf_Page::SHAPE_DRAW_FILL_AND_STROKE)  drawPolygon($x, $y, $fillType = Zend_Pdf_Page::SHAPE_DRAW_FILL_AND_STROKE, $fillMethod = Zend_Pdf_Page::FILL_METHOD_NON_ZERO_WINDING)  drawCircle($x, $y, $radius, $param4 = null, $param5 = null, $param6 = null)
  • 22. Adding images to the page  JPG, PNG and TIFF images are now supported  An example: // Load the image $image = Zend_Pdf_Image::imageWithPath(APPLICATION_FRONT . '/images/logo.tif'); // Draw image $page->drawImage($image, 40, 764, 240, 820); // -> $image, $left, $bottom, $right, $top
  • 23. An example in detail  Here’s a more complete example and the result: $pdf = new Zend_Pdf(); $page = $pdf->newPage(Zend_Pdf_Page::SIZE_A4); $pdf->pages[] = $page; $page->setFont(Zend_Pdf_Font::fontWithName( Zend_Pdf_Font::FONT_HELVETICA), 12); $page->drawText('Hello world!', 50, 600 ); $image = Zend_Pdf_Image::imageWithPath(APPLICATION_FRONT . '/images/logo.tif'); $page->drawImage($image, 40, 764, 240, 820); $page->drawLine(50, 755, 545, 755); $pdf->save('demo.pdf');
  • 25. Using styles  Create styles to combine your own specific layout of pdf in one place:  After creating the style, add some elements to your style  Apply the style $mystyle = new Zend_Pdf_Style(); $mystyle->setFont(Zend_Pdf_Font::fontWithName( Zend_Pdf_Font::FONT_HELVETICA), 12); $mystyle->Zend_Pdf_Color_Rgb(1, 1, 0)); $mystyle->setLineWidth(1); $page1->setStyle($mystyle);
  • 26. Document info  Add information to your document through the properties: $pdf = Zend_Pdf::load($pdfPath); echo $pdf->properties[‘Demo'] . "n"; echo $pdf->properties[‘Dennis'] . "n"; $pdf->properties['Title'] = ‘Demo'; $pdf->save($pdfPath);
  • 27. Advanced topics  Zend_Pdf_Resource_Extractor class for cloning pages and share resources through the different templates  Linear transformations, most of them are available as from ZF 1,8 (skew, scale, …)
  • 28. Summary  Zend_PDF has powerful capabilities  Combining the extended pdf class on framework.zend.com makes life a little easier

Editor's Notes

  1. Working with php for 5 years Develop webapplications and services for medium sized companies Working with zend for 1 year
  2. Special thanks to Inventis for the accomodation.
  3. $this->_helper->layout()->disableLayout(); $this->_helper->viewRenderer->setNoRender();